//
//  NSString+Attributed.m
//  CarWorld
//
//  Created by yuyu on 15/3/27.
//  Copyright (c) 2015年 CarWorldTeam. All rights reserved.
//

#import "NSString+Attributed.h"

@implementation NSString (Attributed)

- (NSAttributedString *)tintSubStringColorWithDictionary:(NSDictionary *)dic
{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self];
    for (NSString *key in dic) {
        NSString *aString = [NSString stringWithFormat:@"%@",key];
        NSRange rang = [self rangeOfString:aString];
        [attributedString setAttributes:@{NSForegroundColorAttributeName:[dic objectForKey:key]} range:rang];
    }
    
    return [attributedString autorelease];
}
- (NSAttributedString *)tintColor:(UIColor *)color subString:(NSString *)subStirng
{
   NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self];
    NSString *aString = [NSString stringWithFormat:@"%@",subStirng];
    NSRange rang = [self rangeOfString:aString];
    [attributedString setAttributes:@{NSForegroundColorAttributeName:color} range:rang];
    
    return [attributedString autorelease];
}

- (NSAttributedString *)tintColorForKeyString:(NSString *)str rang:(NSRange)rang
{
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
    [attributeString setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} range:rang];
    
    return [attributeString autorelease];
}

@end
